package util;

import java.io.IOException;
import java.util.List;

import org.apache.http.HttpHost;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.conn.params.ConnRoutePNames;
import org.apache.http.impl.client.DefaultHttpClient;

import type.DataFactory;
import type.Proxy;

public class TestProxy {
	
	public static void multi(){
		List<Proxy> proxys = DataFactory.getAllProxy();
		System.out.println(proxys.size());
		System.exit(0);
		for(final Proxy py:proxys){
			new Thread(new Runnable(){
				@Override
				public void run() {
			System.out.println(py);
			DefaultHttpClient client = new DefaultHttpClient();
			client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(py.getIp(), Integer.parseInt(py.getPort())));
			try {
				HttpClientUtils.doGetRequest(client, "http://m.mail.163.com", null);
			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
				}}).start();
		}
	}
	public static void single(){
		List<Proxy> proxys = DataFactory.getAllProxy();
		for(Proxy py:proxys){
			System.out.println(py);
			DefaultHttpClient client = new DefaultHttpClient();
			client.getParams().setParameter(ConnRoutePNames.DEFAULT_PROXY, new HttpHost(py.getIp(), Integer.parseInt(py.getPort())));
			try {
				HttpClientUtils.doGetRequest(client, "http://m.mail.163.com", null);
			} catch (ClientProtocolException e) {
				e.printStackTrace();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
	
	/**
	 * @param args
	 */
	public static void main(String[] args) throws Exception{
		multi();

	}

}
